package com._520it.wms.web.interceptor;

import com._520it.wms.domain.Employee;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

//拦截器
public class LoginInterceptor extends HandlerInterceptorAdapter {
    //拦截请求之前的方法
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断当前的用户是否登录 如果没有登录 重定向到登录页面
        //1在session中找到当前登录用户 找到则放行,否则回到登录到页面
        Employee currentUser = (Employee) request.getSession().getAttribute("USER_IN_SESSION");
        if (currentUser == null) {
            response.sendRedirect("/login.jsp");
            return false;
        }
        return true;
    }
}
